import axios from 'axios'
import configs from "../utils/wxapi/config";
var qs = require('qs');
axios.defaults.baseURL = configs.Url;

// axios.defaults.timeout = 10000;
let ajaxList = {
	axios,
	Login: (data) => {
		return axios.post('/api/v3/Login/Login', {
			data
		})
	},
	getSmsCode: (data) => {
		return axios.post('/api/v2/Login/GetSmsCode', {
			data
		})
	},
	GetDetails: (data) => {
		return axios.post('/api/v2/Store/GetDetail', {
			data
		})
	},


	GetOpenToken: (data) => {
		return axios.post('/api/Open/GetOpenToken', {
			data
		})
	},
	GetAppVersion: (data) => {
		return axios.post('/api/SystemVersion/GetAppVersion', {
			data
		})
	},
	GetAllStore: (data) => {
		return axios.post('/api/v2/Store/GetAllStore', {
			data
		})
	},
	GetList: (data) => {
		return axios.post('/api/v2/Store/GetSlideList', {
			data
		})
	},
	GetIndexTagList: (data) => {
		return axios.post('/api/v3/Product/GetIndexTagList', {
			data
		})
	},
	GetProductList: (data) => {
		return axios.post('/api/v3/Product/GetProductList', {
			data
		})
	},
	GetMyCard: (data) => {
		return axios.post('/api/v2/Card/GetMyCard', {
			data
		})
	},

	GetMemberInfo: (data) => {
		return axios.post('/api/v2/Account/GetMemberInfo', {
			data
		})
	},
	IsMemberInfoComplete: (data) => {
		return axios.post('/api/v2/Account/IsMemberInfoComplete', {
			data
		})
	},
	SaveMemberInfo: (data) => {
		return axios.post('/api/v2/Account/SaveMemberInfo', {
			data
		})
	},
	MyOrdersByAPP: (data) => {
		return axios.post('/api/v3/Order/MyOrdersByAPP', {
			data
		})
	},
	OrderPayment: (data) => {
		return axios.post('/api/v3.1/Order/Payment', {
			data
		})
	},
	Logout: (data) => {
		return axios.post('/api/v2/Login/Logout', {
			data
		})
	},
	GetDetail: (data) => {
		return axios.post('/api/v3/Product/GetDetail', {
			data
		})
	},
	CheckCollect: (data) => {
		return axios.post('/api/v3/Product/CheckCollect', {
			data
		})
	},
	AddCollect: (data) => {
		return axios.post('/api/v3/Product/AddCollect', {
			data
		})
	},
	CancelCollect: (data) => {
		return axios.post('/api/v3/Product/CancelCollect', {
			data
		})
	},

	GetICRecord: (data) => {
		return axios.post('/api/v2/Card/GetICRecord', {
			data
		})
	},
	GetTicticket: (data) => {
		return axios.post('/api/v2/Card/GetTicticket', {
			data
		})
	},
	GetMyCollectList: (data) => {
		return axios.post('/api/v3/Product/GetMyCollectList', {
			data
		})
	},
	MemberUnicregist: (data) => {
		return axios.post('/api/v2/Card/MemberUnicregist', {
			data
		})
	},
	MemberIcselfregist: (data) => {
		return axios.post('/api/v2/Card/MemberIcselfregist', {
			data
		})
	},
	Getconsumecode: (data) => {
		return axios.post('/api/v2/Card/Getconsumecode', {
			data
		})
	},
	Checkconsumecode: (data) => {
		return axios.post('/api/v2/Card/Checkconsumecode', {
			data
		})
	},
	GetBalance: (data) => {
		return axios.post('/api/v2/Card/GetBalance', {
			data
		})
	},


	BuyNow: (data) => {
		return axios.post('/api/v3/Order/BuyNow', {
			data
		})
	},
	OrderPreview: (data) => {
		return axios.post('/api/v3.1/Order/OrderPreview', {
			data
		})
	},
	MemberBindCard: (data) => {
		return axios.post('/api/v2/Card/MemberBindCard', {
			data
		})
	},
	PaymentRequest: (data) => {
		return axios.post('/api/v1/Pay/PaymentRequest', {
			data
		})
	},
	ICqrcodeverify: (data) => {
		return axios.post('/api/v3/Card/ICqrcodeverify', {
			data
		})
	},
	CreateOrder: (data) => {
		return axios.post('/api/v3.1/Order/CreateOrder', {
			data
		})
	},
	GetAllStoreByStoreName: (data) => {
		return axios.post('/api/v2/Store/GetAllStoreByStoreName', {
			data
		})
	},
	wxLogin: (data) => {
		return axios.post('/api/v2/WxApp/Login', {
			data
		})
	},
	wxBindPhone: (data) => {
		return axios.post('/api/v2/WxApp/BindMobile', {
			data
		})
	},
	OrderGetDetail: (data) => {
		return axios.post('/api/v3/Order/GetDetail', {
			data
		})
	},


}
axios.interceptors.request.use(function(config) {
	return config;
}, function(error) {
	return Promise.reject(error);
});

axios.defaults.withCredentials = true;

axios.defaults.adapter = function(config) {
	var token = '';
	var u_token = '';
	if (uni.getStorageSync('token_type')) {
		token = uni.getStorageSync('token_type') + " " + uni.getStorageSync('access_token')
	}
	if (uni.getStorageSync('u_token')) {
		u_token = uni.getStorageSync('u_token')
	}
	var setHeader = {
		"Authorization": token || '',
		"u-token": u_token || ''
	}

	if (config.method.toUpperCase() === 'POST') {

		config.data = JSON.parse(config.data).data;

	} else if (config.method.toUpperCase() === 'GET') {

		config.data ? config.data = JSON.parse(config.data) : config.data;
	} else if (config.method.toUpperCase() === 'PUT') {

		config.data = JSON.parse(config.data).data;
	}

	return new Promise((resolve, reject) => {

		uni.request({
			url: configs.Url + config.url,
			method: config.method.toUpperCase(),
			data: config.data == '{}' ? "" : config.data,
			header: setHeader,

			success: (res) => {
				// console.log(res)
				if (res.data.code != 0) {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});

				}
				resolve(res.data)
			},
			fail: err => {
				reject(err)
				// uni.removeStorageSync("u_token");
				// uni.removeStorageSync("access_token");
				// uni.removeStorageSync("token_type");
				// uni.removeStorageSync("userInfo");
				// uni.removeStorageSync("store");
				// uni.removeStorageSync("storeId");
				// uni.removeStorageSync("isLogin");
			},
			complete: (res) => {
				setTimeout(function() {
					uni.hideLoading()
				}, 1500);
				if (res.data.msg == '登录凭证已过期，请重新登陆' || res.data.code == -18) {

					uni.removeStorageSync("u_token");
					uni.removeStorageSync("access_token");
					uni.removeStorageSync("token_type");
					uni.removeStorageSync("userInfo");
					uni.removeStorageSync("store");
					uni.removeStorageSync("storeId");
					uni.removeStorageSync("isLogin");

					uni.reLaunch({
						url: '/pages/commer/wxlogin'
					})
				}
			}
		})


	})
}



module.exports = ajaxList
